<?php include_once 'SVsystem/class/tools.php'; ?>
<?
	$toolSearch = new tools();
        $toolSearch->dbc = $tool->dbc;
	$results = $toolSearch->obtenerCategorias();
?>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript" type="text/javascript">

function getXmlHttpRequestSearchObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?");
	}
}

//Our XmlHttpRequest object to get the auto suggest
var searchReq = getXmlHttpRequestSearchObject();

//Called from keyup on the search textbox.
//Starts the AJAX request.
function searchSuggest(inputString,categoria,precio) {
	if (searchReq.readyState == 4 || searchReq.readyState == 0) {
		searchReq.open("GET", 'SVwidgets/Search/searchSuggest.php?search=' + inputString+'&categoria='+categoria+'&precio='+precio, true);
		searchReq.onreadystatechange = handleSearchSuggest;
		searchReq.send(null);
	}
}


//Called when the AJAX response is returned.
function handleSearchSuggest() {
	if (searchReq.readyState == 4) {
		var ss = document.getElementById('search_suggest')
		ss.innerHTML = '';
		var str = searchReq.responseText.split("\n");
		for(i=0; i < str.length - 1; i++) {
			var suggest = '<div onmouseover="javascript:suggestOver(this);" ';
			suggest += 'onmouseout="javascript:suggestOut(this);" ';
			suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';
			suggest += 'class="suggest_link">' + str[i] + '</div>';
			ss.innerHTML += suggest;
		}
	}
}

//Mouse over function
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
}
//Click function
function setSearch(value) {
	document.getElementById('buscar').value = value;
	document.getElementById('search_suggest').innerHTML = '';
        if (document.getElementById('searchType').value=='simple'){
	        document.getElementById('searchForm').submit();
        }
}
</script>

<style type="text/css" media="screen">
        body {
                font: 11px arial;
        }
        .suggest_link {
                background-color: #FFFFFF;
                padding: 2px 6px 2px 6px;
        }
        .suggest_link_over {
                background-color: #3366CC;
                padding: 2px 6px 2px 6px;
        }
        #search_suggest {
                position: absolute;
                background-color: #FFFFFF;
                text-align: left;
                border: 1px solid #000000;
        }
</style>

</head>

<body>
<div id="buscarsimple" class="chiquitin" >
	<form name="searchForm" id="searchForm" action="SV-resultados-busqueda.php" method="get"
			accept-charset="utf-8" autocomplete="off">
                        <input type="hidden" name="searchType" id="searchType" value="simple">
			<div id="buscartitulo">Encuentre el Producto que Busca...</div>
			<div>
				<input type="text" name="buscar" id="buscar"
					value="<?php echo $_REQUEST['buscar'] ?>"
					title=""
					onkeyup="searchSuggest(this.value,categorias.value,precio.value);" autocomplete="off" />

				<select
					name="categorias" id="categorias" class="apagado">
					<option value="#" selected="selected">En Categoría...</option>
<?php
			for($j=0;$j<count($results);$j++){
				$id = $results[$j]['id'];
				$nombre = $results[$j]['nombre'];
				$hijos = $results[$j]['hijos'];
?>
					<option value="<?php echo $id?>"><?php echo $nombre?></option>
<?php
				for($i=0;$i<count($hijos);$i++){
					$id = $results[$j][$i]['id'];
					$nombre = $results[$j][$i]['nombre'];
					$hijos = $results[$j][$i]['hijos'];
?>
					<option value="<?php echo $id?>">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $nombre?></option>
<?php
	                                for($k=0;$k<count($hijos);$k++){
	                                        $id = $results[$j][$i][$k]['id'];
	                                        $nombre = $results[$j][$i][$k]['nombre'];
?>
					<option value="<?php echo $id?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $nombre?></option>
<?php 					}	?>
<?php 		       		}	?>
<?php 	       		}	?>
				</select>

<select name="precio" id="precio" class="apagado">
					<option value="#" selected="selected">Precio</option>
					<option value="de 0 a 100">de 0 a 100</option>
					<option value="de 101 a 200">de 100 a 200</option>
					<option value="de 201 a 300">de 201 a 300</option>
					<option value="de 301 a 400">de 301 a 400</option>
					<option value="de 401 a 500">de 401 a 500</option>

				</select>

<input type="submit" name="submit-busqueda" value="" id="submit-busqueda" class="apagado">
			</div>
                        <div id="search_suggest">
                        </div>
		<div id="buscarlink">
			<a href="javascript:;"
				onclick="document.getElementById('searchType').value='avanzado';P7_MultiClass2('categorias','prendido','precio','prendido','buscarlink','apagado','buscarlink2','prendido','buscarsimple','grande','submit-busqueda','prendido','suggestions','suggestionsBox2')">Búsqueda
				Avanzada [+]</a>
		</div>
<div id="buscarlink2" class="apagado">
			<a href="javascript:;"
				onclick="document.getElementById('searchType').value='simple';P7_MultiClass2('categorias','apagado','precio','apagado','buscarlink','prendido','buscarlink2','apagado','buscarsimple','chiquitin','submit-busqueda','apagado','suggestions','suggestionsBox')">Búsqueda
				Básica [-]</a>
		</div>

	</form>

</div>
</body>